package arithmetic1.map;


public class MyHashMap<K,V> {
    MyList<Node<K,V>>[] table;
    int size;

    public MyHashMap() {
        table = new MyList[7];
        for (int i = 0; i < 7; i++) {
            table[i] = new MyList<Node<K,V>>();
        }
    }

    private int hash(K k){
        return k==null?0:k.hashCode();
    }

    //添加元素
    public V put(K k,V v){
        int hashCode = hash(k);
        int index = hashCode%7;
        table[index].add(new Node<K,V>(k,v));
        return v;
    }

    //打印哈希表
    public void print(){
        for (int i = 0; i < table.length; i++) {
            table[i].print();
        }
    }
}
